package org.orz.story.pms.biz.web.admin;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.orz.cloud.common.result.ResultDTO;
import org.orz.story.pms.biz.model.req.*;
import org.orz.story.pms.biz.model.resp.ListMenuInfoResp;
import org.orz.story.pms.biz.model.resp.MenuListResp;
import org.orz.story.pms.biz.service.PmsPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "管理端菜单相关接口")
@RestController
@RequestMapping("admin/permission")
public class AdminPermissionController {

    @Autowired
    private PmsPermissionService pmsPermissionService;

    @PostMapping("getAdminMenuList")
    @ApiOperation("查询管理端菜单列表")
    public ResultDTO<List<MenuListResp>> getAdminMenuList(){
        return ResultDTO.success(pmsPermissionService.getAdminMenuList());
    }

    @PostMapping("listMenuInfoOfTree")
    @ApiOperation("查询树形菜单列表")
    public ResultDTO<List<MenuListResp>> listMenuInfoOfTree(@RequestBody ListMenuInfoOfTreeReq req){
        return ResultDTO.success(pmsPermissionService.listMenuInfoOfTree(req));
    }

    @ApiOperation("条件查询菜单列表")
    @PostMapping("listMenuInfo")
    public ResultDTO<List<ListMenuInfoResp>> listMenuInfo(@RequestBody ListMenuInfoReq req){
        return ResultDTO.success(pmsPermissionService.listMenuInfo(req));
    }

    @ApiOperation("添加权限")
    @PostMapping("addPermission")
    public ResultDTO<Boolean> addPermission(@RequestBody AddPermissionReq req){
        pmsPermissionService.addPermission(req);
        return ResultDTO.success();
    }

    @ApiOperation("修改权限")
    @PostMapping("updatePermission")
    public ResultDTO<Boolean> updatePermission(@RequestBody UpdatePermissionReq req){
        pmsPermissionService.updatePermission(req);
        return ResultDTO.success();
    }

    @ApiOperation("删除权限")
    @PostMapping("deletePermission")
    public ResultDTO<Boolean> deletePermission(@RequestBody DeletePermissionReq req){
        pmsPermissionService.deletePermission(req);
        return ResultDTO.success();
    }

    @PostMapping("grantPermission")
    @ApiOperation("给角色分配权限")
    public ResultDTO<Boolean> grantPermission(@RequestBody GrantPermissionReq req){
        pmsPermissionService.grantPermission(req);
        return ResultDTO.success();
    }

    @PostMapping("addPermissionApi")
    @ApiOperation("权限新增接口")
    public ResultDTO<Boolean> addPermissionApi(@RequestBody GrantPermissionApiReq req){
        pmsPermissionService.addPermissionApi(req);
        return ResultDTO.success();
    }

    @PostMapping("deletePermissionApi")
    @ApiOperation("权限删除接口")
    public ResultDTO<Boolean> deletePermissionApi(@RequestBody DeletePermissionApiReq req){
        pmsPermissionService.deletePermissionApi(req);
        return ResultDTO.success();
    }
}
